﻿using CrateMayhem.Common.Controls;
using CrateMayhem.WinRT.Common;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace CrateMayhem.WinRT.Controls
{
    public class Crate : UserControl, ICrate
    {
        private static readonly Brush brush;
        private static readonly Brush targetBrush;
        private static readonly Brush borderBrush;
        private readonly Border border;

        public Crate()
        {
            DefaultStyleKey = typeof(Crate);
            border = new Border
            {
                CornerRadius = new CornerRadius(2),
                BorderThickness = new Thickness(1),
                Background = brush,
                BorderBrush = borderBrush
            };
            Content = border;
        }

        static Crate()
        {
            brush = Common.Resources.GameStyles.Get<Brush>("CrateBackgroundBrush");
            targetBrush = Common.Resources.GameStyles.Get<Brush>("CrateOnTargetBackgroundBrush");
            borderBrush = Common.Resources.GameStyles.Get<Brush>("BrickBorderBrush");
        }

        public void UpdateBrush(bool onTarget)
        {
            border.Background = onTarget ? targetBrush : brush;
        }
    }
}